package filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

//1. implements Filter
//2. no-arg 생성자
//3. public class 로 작성
//4. life cycle메소드 overriding
public class TestFilter implements Filter {

	public TestFilter() {
		System.out.println("TestFilter 생성자 실행");
	}

	@Override
	public void destroy() {
		// Servlet의 destroy()
		System.out.println("TestFilter.destroy() 실행");

	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		// servlet-service()역할
		// FilterChain - 다음에 호출될 component정보

		//전처리 작업
		System.out.println("TestFilter chain.doFilter() 호출 전");
		chain.doFilter(request, response); //다음에 호출될 component 호출하는 메소드
		//후처리 작업
		System.out.println("TestFilter chain.doFIlter() 호출 후");

	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		// Servlet - init(), FilterConfig : ServletConfig의 역할. 초기 파라미터 조회
		System.out.println("TestFilter.init()");

	}

}